package com.jade.logger;

import java.text.SimpleDateFormat;
import java.util.Date;

import org.eclipse.core.runtime.FileLocator;
import org.eclipse.core.runtime.Path;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.swt.graphics.Image;


public class Message {
	
	private String _text;
	private String _state;
	private String _time;
	
	public static String STATE_ERROR = "ERROR";
	public static String STATE_DELETE = "DELETE";
	public static String STATE_INFO = "INFO";
	public static String STATE_SUCCESS = "SUCCESS";
	public static String STATE_WARNING = "WARN";
	public static String STATE_EMPTY = "EMPTY";
	
	public Message(String state, String text){
		_state = checkState(state);
		_text = text;
		
		Date dNow = new Date( );
		SimpleDateFormat ft = new SimpleDateFormat ("HH:mm:ss");

		_time = ft.format(dNow);
		
	}
	
	
	public void setText(String text){
		_text = text;
	}
	
	
	public void setState(String state){
		_state = checkState(state);
	}
	
	
	public void setTime(){
		Date dNow = new Date( );
		SimpleDateFormat ft = new SimpleDateFormat ("HH:mm:ss");

		_time = ft.format(dNow);
	}
	
	
	public String getText(){
		return _text;
	}
	
	
	public String getState(){
		return _state;
	}
	
	
	public String getTime(){
		return _time;
	}
	
	
	public Image getImage(){
		
		ImageDescriptor myImage = ImageDescriptor.createFromURL(FileLocator.find(Activator.getDefault().getBundle(), new Path("icons/" + getImgName() + ".png"),null));
		return myImage.createImage();
	}
	
	
	public ImageDescriptor getImageDescriptor(){
		return ImageDescriptor.createFromURL(FileLocator.find(Activator.getDefault().getBundle(), new Path("icons/" + getImgName() + ".png"),null));
	}
	
	
	private String getImgName(){
		switch(_state){
		case "ERROR" : return "ICON_ERROR";
		case "DELETE" : return "ICON_DELETE";
		case "INFO" : return "ICON_INFORMATION";
		case "SUCCESS" : return "ICON_SUCCESS";
		case "WARN" : return "ICON_WARNING";
		case "EMPTY" : return "ICON_EMPTY";
		default : return "ICON_EMPTY";
		}
	}
	
	
	private String checkState(String state){
		switch(state){
		case "ERROR" : return "ERROR";
		case "DELETE" : return "DELETE";
		case "INFO" : return "INFO";
		case "SUCCESS" : return "SUCCESS";
		case "WARN" : return "WARN";
		case "EMPTY" : return "EMPTY";
		default : return "EMPTY";
		}
	}
}
